// pages/fb_my/fb_my.js
import tool from '../../modules/tool'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dateList: undefined,
    feedBackList: undefined,
    selected: ''
  },

  handleShowDetail(e) {
    e = e.target.dataset
    tool.feedback.showDetailPage(e.id)
  },

  async handleChange(e) {
    e = e.target.dataset.date
    await tool.flow(async () => {
      let re = await tool.feedback.getMy(e.date, this.data.openId)
      this.setData({
        ...re,
        selected: e.read,
        selectedDate: e.date
      })
    }, async err => {
      wx.navigateBack()
      await tool.wait(0.4)
      tool.refreshHomeData()
      wx.showToast({
        title: `${err}`,
        duration: 800,
        icon: 'error'
      })
    })
  },

  handleBack() {
    wx.navigateBack()
  },

  handleShowOp(e) {
    e = e.target.dataset
    tool.handleShowActionSheet([
      ...tool.formPageControls.list.conditionItem(e.item?.per?.withdraw, () => ({
        name: '撤回',
        callBack: () => tool.feedback.delete(e.item.id)
      }))
    ])
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    tool.store.onChange('feedBack_my_refresh', () => {
      this.handleChange({
        target: {
          dataset: {
            date: {
              date: this.data.selectedDate ? this.data.selectedDate : this.data.dateList[0].date,
              read: this.data.selectedDate ? this.data.selected : this.data.dateList[0].read,
            }
          }
        }
      })
    })
    tool.setPageData(this)
    let data = tool.store.getItem('feedBack_my')
    tool.store.removeItem('feedBack_my')
    if (data) {
      this.setData(data.data)
      this.setData({
        openId: data.openId,
        openId_read: data.openId_read
      })
    } else {
      wx.navigateBack()
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})